<template>
	<!-- 富文本 -->
	<view class="diy-richText" :style="[{'background': background }, {'padding-top': paddingTop},{'padding-left':paddingLeft},{'padding-right':paddingLeft},{'padding-bottom': paddingTop}]">
			<rich-text :nodes="getcontent"></rich-text>
	</view>
</template>

<script>
	export default {
		computed: {
			paddingTop() {
				return uni.upx2px(this.itemStyle.paddingTop * 2) + 'px';
			},
			background() {
				return this.itemStyle.background;
			},
			paddingLeft() {
				return uni.upx2px(this.itemStyle.paddingLeft * 2) + 'px';
			},
			getcontent(){
				let article = this.params.content.replace(/<img/, "<img style='max-width:100%;height:auto;'");
				return article;
			}
		},
		props: {
			itemStyle: {},
			params: {}
		},
		methods: {
			/*2.用正则表达式实现html解码*/
			htmlDecodeByRegExp: function(str) {
				var s = "";
				if (str.length == 0) return "";
				s = str.replace(/&amp;/g, "&");
				s = s.replace(/&lt;/g, "<");
				s = s.replace(/&gt;/g, ">");
				s = s.replace(/&nbsp;/g, " ");
				s = s.replace(/&#39;/g, "\'");
				s = s.replace(/&quot;/g, "\"");
				return s;
			},
		},
		  data() {
		        return {
		            nodes: [{
		                name: 'div',
		                attrs: {
		                    class: 'div-class',
		                    style: 'line-height: 60px; color: red; text-align:center;'
		                },
		                children: [{
		                    type: 'text',
		                    text: 'Hello&nbsp;uni-app!'
		                }]
		            }],
		            strings: '<div style="text-align:center;"><img src="https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/uni@2x.png"/></div>'
		        }
		    }
	}
</script>

<style>
	/* common.wxss */
	/* @import url("../../utils/common.scss"); */
	.diy-richText {
		font-size: 28upx;
	}
</style>
